package cn.ytxy.ivos.dictoption.controller;


import cn.ytxy.ivos.base.response.JsonResult;
import cn.ytxy.ivos.dictoption.pojo.dto.DictOptionQuery;
import cn.ytxy.ivos.dictoption.pojo.dto.DictOptionSaveParam;
import cn.ytxy.ivos.dictoption.pojo.vo.DictOptionVO;
import cn.ytxy.ivos.dictoption.service.DictOptionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName DictOptionController
 * @Description TODO
 * @Author renhong~Deng
 * @Date 2025/5/12 11:03
 * @Version 1.0
 */
@Slf4j
@RestController
@RequestMapping("/v1/dictoption/")
public class DictOptionController {

    @Autowired
    DictOptionService dictOptionService;

    @GetMapping("/select")
    public JsonResult selectDictOption(DictOptionQuery dictOptionQuery) {
        log.debug("查询字典项参数：{}", dictOptionQuery);
        List<DictOptionVO> dictOptionVOS = dictOptionService.selectDictOption(dictOptionQuery);
        return JsonResult.ok(dictOptionVOS);
    }

    @PostMapping("/save")
    public JsonResult saveDictOption(DictOptionSaveParam dictOptionSaveParam) {
        log.debug("保存字典项参数：{}", dictOptionSaveParam);
        dictOptionService.saveDictOption(dictOptionSaveParam);
        return JsonResult.ok();
    }


    @GetMapping("/select/{code}")
    public JsonResult selectDictOptionByCode(@PathVariable String code) {
        log.debug("查询字典项参数：{}", code);
        List<DictOptionVO> dictOptionVOS = dictOptionService.selectDictOptionByCode(code);
        return JsonResult.ok(dictOptionVOS);
    }

    @PostMapping("/delete/{id}")
    public JsonResult deleteDictOption(@PathVariable Long id) {
        log.debug("删除字典项参数：{}", id);
        dictOptionService.deleteDictOption(id);
        return JsonResult.ok();
    }
}
